import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool {
    //模拟实现线程池
    private Thread[] pool;
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

    public MyThreadPool(int capacity) {
        for (int i = 0; i < capacity; i++) {
            int id = i;
            Thread t = new Thread(() -> {
                while(true) {
                    Runnable task = null;
                    try {
                        task = queue.take();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    task.run();
                }
            },"threadPool" + id);
            t.start();
            pool[i] = t;
        }
    }

    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }
}

class Singleton {
    private Singleton instance = new Singleton();

    private Singleton() {}

    public Singleton getInstance() {
        return instance;
    }
}

class SingletonLazy {
    private SingletonLazy instance;
    private Object locker = new Object();

    private SingletonLazy() {}

    public SingletonLazy getInstance() {
        if(instance == null) {
            synchronized (locker) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
}

public class Demo2 {
    public static void main(String[] args) {

    }
}
